//
//  HomeViewController.m
//  AILove
//
//  Created by 甘世清 on 2023/12/15.
//

#import "HomeViewController.h"
#import "LoveViewController.h"
#import "AllViewController.h"
@interface HomeViewController ()
@property (nonatomic , strong)AllViewController * allVc;
@property (nonatomic , strong)LoveViewController * loveVc;
@property (nonatomic , strong) UIImageView * leftImage;
@property(nonatomic , strong) UILabel * topLabel;
@end

@implementation HomeViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([[Manager SQ_stringForKey:@"获得角色"] isNotEmpty]) {
        self.leftImage .hidden = YES;
        self.topLabel .hidden = YES;
        [self setTabBarFrame:CGRectMake(70, TopHeight-40, SCREEN_WIDETH-140, 40)
            contentViewFrame:CGRectMake(0, TopHeight, SCREEN_WIDETH, SCREEN_HEIGHT-TopHeight-FootHeight-40)];
        [self.tabBar setIndicatorWidth:30 marginTop:34 marginBottom:2 tapSwitchAnimated:YES];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor  = UIColor.blackColor;
    [self SQ_uiViewForSelf];
}
-(void)SQ_uiViewForSelf{
    self.tabContentView.delegate  =self;
    self.tabBar.itemTitleFont = FONT_BOLD(18);
    self.tabBar.indicatorImage = SQGetImage(@"按钮背景");
    self.tabBar.itemTitleSelectedFont = FONT_BOLD(18);
    self.tabBar.itemTitleColor = SQHexColor(@"#FFFFFF", 0.7);
    self.tabBar.itemTitleSelectedColor = UIColor.whiteColor;
    self.tabBar.backgroundColor = UIColor.blackColor;
    [self setTabBarFrame:CGRectMake(70, TopHeight-50, SCREEN_WIDETH-140, 60)
        contentViewFrame:CGRectMake(0, TopHeight+20, SCREEN_WIDETH, SCREEN_HEIGHT-TopHeight-FootHeight-70)];
    self.viewControllers = [NSMutableArray arrayWithObjects:self.allVc, self.loveVc,nil];
    [self.tabBar setIndicatorWidth:30 marginTop:44 marginBottom:12 tapSwitchAnimated:YES];
    
    [self.view addSubview:self.leftImage];
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view).offset(35);
            make.width.mas_equalTo(52);
            make.height.mas_equalTo(23);
        make.top.equalTo(self.tabBar).offset(32);
    }];
    [self.view addSubview:self.topLabel];
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.leftImage).offset(4);
            make.top.equalTo(self.leftImage.mas_bottom).offset(0);
    }];
   
    [Manager SQ_SetObject:@"获得角色" FormKey:@"获得角色"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:@"doubleClick" object:nil];
}

-(void)reloadData{
    NSLog(@"我来刷新了");
    if (self.tabContentView.selectedController == self.loveVc) {
        [self.loveVc refreshData];
    }else{
        [self.allVc refreshData];
    }
}

/**
 *  点击了index
 */
- (void)tabContentView:(YPTabContentView *)tabConentView didClickedTabAtIndex:(NSUInteger)index{
    if (index==1) {
        [self.loveVc SQ_Header];
    }
}
- (AllViewController *)allVc{
    if (!_allVc) {
        _allVc = [[AllViewController alloc]init];
        _allVc.yp_tabItemTitle = SQNSLocalString(@"获得角色");
        
    }
    return _allVc;
}
- (LoveViewController *)loveVc{
    if (!_loveVc) {
        _loveVc = [[LoveViewController alloc]init];
        _loveVc.yp_tabItemTitle = SQNSLocalString(@"我喜欢的");
        
    }
    return _loveVc;
}

- (UIImageView *)leftImage{
    if (!_leftImage) {
        _leftImage = [[UIImageView alloc]init];
        _leftImage.image = SQGetImage(@"线条");
        _leftImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _leftImage;
}

- (UILabel *)topLabel{
    if (!_topLabel) {
        _topLabel = [[UILabel alloc]init];
        _topLabel.text = SQNSLocalString(@"刷新出的新角色，都会显示在这里");
        _topLabel.textColor = SQColor(@"#B9B8B7");
        _topLabel.font = FONT_BOLD(12);
    }
    return _topLabel;
}
@end
